package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.model.TbBrand;
import com.dongdongshop.page.PageParms;
import com.dongdongshop.page.PageResult;
import com.dongdongshop.service.BrandService;
import com.dongdongshop.vo.BrandVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("brand")
public class BrandController {
    @Autowired
    private BrandService brandService;
    @PostMapping("findBrandPage")
    public Result brandList(@RequestBody PageParms<BrandVO> page) {
        PageResult brandList =  brandService.findBrand(page);
        return Result.OK().setData(brandList);
    }

    /*@PostMapping("findBrandPage")
    public Result brandList(@RequestBody BrandVO vo) {
        List<BrandVO> brandList =  brandService.findBrands(vo);
        return Result.OK().setData(brandList);
    }*/

    @PostMapping("addBrandVO")
    @ApiOperation(value = "增加商品品牌")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "brandVO",value = "增加的商品品牌",paramType = "body")
    })
    public Result addBrandVO(@RequestBody BrandVO brandVO){
        brandService.addBrandVO(brandVO);
        return Result.OK();
    }

    @PostMapping("delete")
    @ApiOperation(value = "删除商品品牌")
    public Result deleteBrandVO(@RequestParam Long[] ids){
        brandService.deleteBrandVO(ids);
        return Result.OK();
    }

    @PostMapping("updateBranVO")
    @ApiOperation(value = "修改商品品牌")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "brandVO",value = "修改商品品牌",paramType = "body")
    })
    public Result updateBranVO(@RequestBody BrandVO brandVO){
        brandService.updateBranVO(brandVO);
        return Result.OK();
    }

    //根据id查询
    @PostMapping("findBrandById")
    public Result findBrandById(@RequestParam Long id) {
        BrandVO brandVO = brandService.findBrandById(id);
        return Result.OK().setData(brandVO);
    }

    @PostMapping("getAll")
    public Result getAll(){
        List<TbBrand> list = brandService.getAll();
        return Result.OK().setData(list);
    }
}
